//------------------------------------------------------------------------------
// Copyright (c) 2008 www.dnaide.com
// Licensed under the MIT (MIT-LICENSE.txt)
//------------------------------------------------------------------------------
using System;

namespace DNAide.Data
{

	/// <summary>
	/// Data helper methods.
	/// </summary>
	public static partial class DataAide
	{

		/// <summary>
		/// Calculates total pages given a total number of records and a page size
		/// </summary>
		/// <param name="totalRecords">totalRecords</param>
		/// <param name="pageSize">pageSize</param>
		/// <returns>Int32</returns>
		public static Int32 CalculateTotalPages(Int32 totalRecords, Int32 pageSize)
		{
			if (totalRecords < 1 || pageSize < 1)
			{
				return 0;
			}

			// First calculate the division
			int retval = totalRecords / pageSize;

			// Now do a mod for any remainder
			if ((totalRecords % pageSize) > 0)
				retval++;

			return retval;
		}

	}
}
